import axios from 'axios'

const instance = axios.create({
  baseURL: 'http://127.0.0.1:3000/',
  timeout: 1000,
  headers: {'Content-Type': 'application/json'}
})

// axios.defaults.baseURL = 'http://127.0.0.1:3000/'
axios.defaults.headers.common['Authorization'] = '123'
instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

instance.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  console.log(response)
  return response
}, function (error) {
  // 对响应错误做点什么
  console.log(error)
  return Promise.reject(error)
})

export default {
  install(Vue) {
    Vue.prototype.$http = instance
  }
}
